package com.shitu.base.utils;

import android.content.Context;
import android.content.SharedPreferences;

/**
 * SharedPreference简单封装
 * 使用apply来提高性能，不适合跨进程
 * 后续再考虑复杂逻辑
 * Created by majie on 17/10/16.
 */

public class SP {
    private static SharedPreferences preferences;
    private static SharedPreferences.Editor editor;
    private static final String SP_NAME = "projxsp";

    public static void init(Context context) {
        preferences = context.getSharedPreferences(SP_NAME, context.MODE_PRIVATE);
        editor = preferences.edit();
    }

    public static void put(String key, String value) {
        editor.putString(key, value);
        editor.apply();
    }

    public static void clear(String key) {
        editor.remove(key);
        editor.apply();
    }

    public static String get(String key) {
        return preferences.getString(key, "");
    }

    public static int get(String key, int defValue) {
        return preferences.getInt(key, defValue);
    }

    public static void put(String key, int value) {
        editor.putInt(key, value);
        editor.apply();
    }

}
